import { defineStore } from 'pinia'

export const useThemeStore = defineStore('theme', {
  state: () => ({
    isDark: false
  }),
  actions: {
    toggleTheme() {
      this.isDark = !this.isDark
      // 切换 element-plus 的主题
      document.documentElement.className = this.isDark ? 'dark' : ''
      // 保存到本地存储
      localStorage.setItem('theme', this.isDark ? 'dark' : 'light')
    },
    initTheme() {
      // 从本地存储获取主题设置
      const theme = localStorage.getItem('theme')
      this.isDark = theme === 'dark'
      document.documentElement.className = this.isDark ? 'dark' : ''
    }
  }
}) 